package com.br.unisal.library.database.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConnection {
	private static final String DATABASE_LOCATION = "biblioteca.db";
	private static Connection  connection;


	private DatabaseConnection() {
		createConnection();
	}
	
	private void createConnection() {
		try {
			Class.forName("org.sqlite.JDBC");
			connection = DriverManager.getConnection("jdbc:sqlite:"+ DATABASE_LOCATION);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}     
	}

	public synchronized static Connection getInstance() {
		if(connection == null) {
		 new DatabaseConnection();
		}
		return connection;
	}
}
